package com.link.base.base.email.controller;

import com.link.base.base.email.model.EmailItem;
import com.link.base.base.email.service.EmailItemService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.Filter;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/12 9:27
 * @version 1.0
 */

@Controller
@RequestMapping("/link/emailItem")
public class EmailItemController extends BasicController<EmailItem> {

    @Resource
    private EmailItemService emailItemService;

    @Override
    public BasicService<EmailItem> getBasicService() throws Exception {
        return emailItemService;
    }

    /**
     * 预处理：存在父子级联，所以强制父Id不能为空
     */
    @Override
    public void beforQueryAllOrExample(EmailItem entity, HttpServletRequest request) throws Exception {
        QueryParams qps = entity.getQps();
        if (qps != null) {
            List<Filter> filterList = qps.getFilterByProperty("emailId");
            if (filterList == null || filterList.size() == 0) {
                qps.addFilter(new Filter("emailId", "noMatchId"));
            }
        }
        BasicModel.transformClass(entity, qps);
    }

}
